package com.tzxs.pay.main.mine.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.databinding.ObservableField;
import android.support.annotation.NonNull;
import android.util.Log;

import com.tzxs.pay.main.login.model.User;
import com.tzxs.pay.util.ISharedPreference;
import com.tzxs.pay.util.SingleLiveEvent;
import com.tzxs.pay.util.netnavigator.SimpleNetNavigator;
import com.tzxs.pay.util.viewmodel.Callback;

public class MineViewModel extends AndroidViewModel {

    private static final String TAG = MineViewModel.class.getSimpleName();
    public SingleLiveEvent<String> snackEvent = new SingleLiveEvent<>();
    public SingleLiveEvent<String> dialogEvent = new SingleLiveEvent<>();


    //名字  手机号
    public final ObservableField<String> name = new ObservableField<>();
    public final ObservableField<String> phone = new ObservableField<>();


    public MineViewModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 获取用户信息
     */
    public void getUserInfo(final Callback callback) {

        String token = ISharedPreference
                .getInstance(getApplication()).getToken();
        MineDataResource.getInstance(getApplication()).getUserInfo(token, new SimpleNetNavigator<User>(snackEvent, dialogEvent, callback) {
            @Override
            public String getTitle() {
                return null;
            }

            @Override
            public void success(User data) {
                name.set(data.getData().getName());
                phone.set(data.getData().getPhone());

                Log.d(TAG, "success: name:" + data.getData().getName());
                Log.d(TAG, "success: phone:" + data.getData().getPhone());
                callback.success();
            }
        });
    }


}
